import Base from 'models/base';

import SystemUtil from 'utils/systemUtil';

export default class ShopGoods extends Base {
  constructor(goods) {
    super();

    this.id = goods.goodsDefId;
    this.defId = goods.goodsDefId;
    this.name = goods.goodsName;
    this.pic = this.getOnePic(goods.goodsPic);
    this.price = goods.goodsModelSalePrice;
    this.sourcePrice = goods.goodsModelSourcePrice;
    this.buyMethod = goods.buyMethod;

    let typeIds = goods.goodsMajorType;
    if (SystemUtil.isEmpty(typeIds)) {
      typeIds = [];
    } else {
      typeIds = JSON.parse(typeIds);
    }
    this.typeIds = typeIds;

    let modelList = goods.modelList;
    let modelIds = [];
    for (let i = 0; i < modelList.length; i++) {
      modelIds.push(modelList[i].goodsModelId);
    }
    this.modelIds = modelIds;
  }
}